#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/licenses/gpl.txt

from inary.actionsapi import autotools
from inary.actionsapi import inarytools
from inary.actionsapi import shelltools
from inary.actionsapi import get

def setup():
    inarytools.flags.add("-fPIC -D_GNU_SOURCE")
    lib = ""
    autotools.autoreconf("-fi")
    if get.buildTYPE() == "emul32":
        shelltools.export("CC","gcc -m32")
        shelltools.export("CXX","g++ -m32")
        lib+="32"
    shelltools.reset_env()
    autotools.configure("--libdir=/lib{0} \
                         --disable-nls \
                         --enable-audit \
                         --enable-securedir=/lib{0}/security \
                         --enable-isadir='.'".format(lib))

    inarytools.dosed("libtool", " -shared ", " -Wl,-O1,--as-needed -shared ")

def build():

    autotools.make()

def check():
    autotools.make("check")

    # dlopen check
    if get.buildTYPE() == "emul32":
        shelltools.export("CC","gcc -m32")
        shelltools.export("CXX","g++ -m32")
    else:
        shelltools.export("CC","gcc")
        shelltools.export("CXX","g++")
    shelltools.system("chmod 755 ./dlopen.sh")
    shelltools.system("chmod 755 ./dlopen-test.sh")
    shelltools.system("./dlopen-test.sh")

def install():
    autotools.rawInstall("DESTDIR=%s" % get.installDIR())
    if get.buildTYPE()=="emul32":
        return

    inarytools.removeDir("/usr/share/doc/Linux-PAM/")

    inarytools.doman("doc/man/*.[0-9]")
    inarytools.dodoc("CHANGELOG", "Copyright", "README")
